
public class Test05 {
    public static void main(String[] args) {
        System.out.println(" ");

        int[] array={1,2,3,4,5};
        double avg=getAvg(array);
        System.out.println("该数组的平均值是："+avg);
        
    }
    
    public static double getAvg(int [] arr){
        //遍历数组求和
        double avg=0.0;
        int sum=0;
        for(int i=0;i<arr.length;i++){
            sum+=arr[i];
        }
       
        int num =arr.length;
        avg=sum/num;
        return avg;
    }
}
